package middleware

import (
	"XSSS_v2/handler"
	"XSSS_v2/pkg/errno"
	"XSSS_v2/pkg/token"
	"github.com/gin-gonic/gin"
)

//登陆认证中间件
func AuthLogin() gin.HandlerFunc {
	return func(c *gin.Context) {
		context, err := token.ParseRequest(c)
		c.Set("user", context.Username)
		c.Set("obj", context.Obj)
		if err != nil {
			handler.SendResponse(c, errno.ErrTokenInvalid, nil)
			c.Abort()
		}
		c.Next()
	}
}
